/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-06-10
 * Time: 17:13
 */
public class Deom14 {
    public static int count = 0;
    /*synchronized public void add() {
        count++;
    }*/
    public void add() {
        synchronized (this) {
            count++;
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Deom14 deom14 = new Deom14();
        Thread t1 = new Thread(()-> {
            for (int i = 1; i <= 5000; i++) {
                deom14.add();
            }
        });
        Thread t2 = new Thread(()-> {
            for (int i = 1; i <=5000 ; i++) {
                deom14.add();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count = "+ count);
    }
}
